package java05;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		
		ArrayListIntegerStack list = new ArrayListIntegerStack();
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			Integer m = new Integer(in.nextInt());
			System.out.println(list.push(m));
		}
		System.out.println(list.peek()+ "," + list.empty() + "," + list.size());
		System.out.println(list);
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(list.pop());
		}
		System.out.println(list.peek()+ "," + list.empty() + "," + list.size());
		System.out.println(list);
		
	}

}


/*interface IntegerStack {
	public Integer push(Integer item);//如item为null，则不入栈直接返回null。如栈满，也返回null.
	public Integer pop();//出栈，如为空，则返回null.
	public Integer peek();//获得栈顶元素，如为空，则返回null.
	public boolean empty();//如为空返回true
	public int size();//返回栈中元素数量
	
	
}

class ArrayListIntegerStack implements IntegerStack{

	private List<Integer> list;
	
	public ArrayListIntegerStack(){
		list = new ArrayList<Integer>();
	}
	@Override
	public Integer push(Integer item) {
		if(item == null) return null;
		list.add(item);
		return item;
	}

	@Override
	public Integer pop() {
		if(list.size() == 0)return null;
		return list.remove(list.size() - 1);
	}

	@Override
	public Integer peek() {
		if(list.isEmpty()) return null;
		return list.get(list.size() - 1);
	}

	@Override
	public boolean empty() {
		if(list.isEmpty())return true;
		return false;
	}

	@Override
	public int size() {
		
		return list.size();
	}
	@Override
	public String toString() {
		return list.toString();
	}	
}*/